﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HKEA.CMS.Core.Utility;
using HKEA.CMS.Core.BLL;
using HKEA.CMS.Core.Models;
using System.Transactions;
using HKEA.Exporter.BLL;
using HKEA.Exporter.Models;
using System.IO;
using System.Data.Objects;
using System.Transactions;
using HKEA.CMS.Core.DAL.App;
using HKEA.CMS.Core.BLL.Mtbl;
using HKEA.CMS.Core.BLL.Tbl;
using HKEA.CMS.Core.BLL.Rej;
using HKEA.CMS.Core.BLL.Stg;
using System.ComponentModel;
using System.Data.SqlClient;
namespace WebApplication
{
    public partial class WebForm1 : BasePage
    {
        protected int customeruid = 0;
        protected int branduid = 0;
        tblCustomer customerENT = new tblCustomer();
        tblCustomerBLL customerBLL = new tblCustomerBLL();
        mtblBrandBLL brandBLL = new mtblBrandBLL();

        tblBrand_ProdCat brand_prodCatENT = new tblBrand_ProdCat();
        tblBrand_ProdCatBLL brand_prodCatBLL = new tblBrand_ProdCatBLL();
        
        
        ActivityTypeBLL HKEA_TypeBLL = new ActivityTypeBLL();
        ActivityBLL HKEA_BLL = new ActivityBLL();
        tblActiviteBLL CMS_BLL = new tblActiviteBLL();
        mtblActiviteTypeBLL CMS_TypeBLL = new mtblActiviteTypeBLL();

        TimeSpan TimeSpanDetachALL = new TimeSpan();
        TimeSpan TimeSpanGetNeedToDel = new TimeSpan();
        TimeSpan TimeSpanGetNeedToAdd = new TimeSpan();
        TimeSpan TimeSpanSaveDNC = new TimeSpan();
        TimeSpan TimeSpanFinishAll = new TimeSpan();
        TimeSpan TimeSpanUpdateInfo = new TimeSpan();
        DateTime Begin = DateTime.Now;
        DateTime End = DateTime.Now;
        string connStringUsePool = "server=.;database=pubs;uid=sa;pwd=123456;pooling=true;connection lifetime=0;min pool size = 1;max pool size=50";
        string connStringUnUsePool = "server=.;database=pubs;uid=sa;pwd=123456;pooling=false";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
              //  var s= TypeDescriptor.GetConverter(t).ConvertFrom(Source);
                //DateTime times = Convert.ToDateTime(str);
                
                //app_tblContactPerson cp = new app_tblContactPerson();
                //cp.SalutationUID = 1;
                //cp.Deleted = 0;
                //cp.LastModifyDate = DateTime.Now;
                //cp.CreationDate = DateTime.Now;
                //HKEA_CMSEntities models = new HKEA_CMSEntities();
                //models.app_tblContactPerson.AddObject(cp);
                //models.SaveChanges();
                //app_mtblBrandDAL dal =app_mtblBrandDAL.GetInstance();
                //app_mtblBrand ent = new app_mtblBrand();
                //ent.CreationDate = DateTime.Now;
                //ent.CustomerUID = 2;
                //ent.LastModifyDate = DateTime.Now;
                //dal.InsertENT(ent); 
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {

            int count = 50;
            DateTime start = DateTime.Now;
            for (int i = 0; i < count; i++)
            {
                using (SqlConnection conn = new SqlConnection(connStringUsePool))
                {
                    conn.Open();
                    conn.Close();
                }
            }
            DateTime end = DateTime.Now;
            TimeSpan ts = end - start;
            string str= "使用连接池" + ts.Milliseconds.ToString();
            start = DateTime.Now;

            for (int i = 0; i < count; i++)
            {
                using (SqlConnection conn = new SqlConnection(connStringUnUsePool))
                {
                    conn.Open();
                    conn.Close();
                }
            }
            end = DateTime.Now;
            ts = end - start;
            string str2 = "不使用连接池" + ts.Milliseconds.ToString();
        }


        protected void Button1_Click(object sender, EventArgs e)
        {

           // SyncActivity();
           // DNCOption();
        }

        #region rej表测试
        private void RejTest()
        {
            rej_tblAddress address = new rej_tblAddress();
            rej_tblAddressBLL bll = new rej_tblAddressBLL();
            address.AddressUID = 1;
            address.Area_Chi = "test";
            address.Area_Eng = "test";
            address.CountryUID = 6;
            address.CreationDate = DateTime.Now;
            address.RejectedDate = DateTime.Now;

            bll.InsertENT(address);
        }
        #endregion


        #region DNC处理

        private void DNCOption()
        {
            var source=GetSource();

            DateTime begin = DateTime.Now;
            var All= DetachNoFromTxt();

            DateTime finishALL = DateTime.Now;
            TimeSpanDetachALL = finishALL - begin; //分离DNC所有号码所耗时间

            var NeedToDel = GetNeedToDelOfDNC(All, source);
            DateTime finishDel = DateTime.Now;
            TimeSpanGetNeedToDel = finishDel - finishALL; //分离需要被删除DNC所耗时间

            var TempNeedToAdd = GetNeedToAddOfDNC(All, source);
            var NeedToAdd = TempNeedToAdd.Distinct().ToList();
            DateTime finishAdd = DateTime.Now;
            TimeSpanGetNeedToAdd = finishAdd - finishDel; //分离需要被新增DNC所耗时间

            SaveDNC(NeedToDel, TempNeedToAdd,All);
        }

        private List<mtblDNC> GetSource()
        {
            HKEA_CMSEntities models = new HKEA_CMSEntities();
            var Source = models.mtblDNCs.Where(a => !string.IsNullOrEmpty(a.NumberValue)).ToList();
            return Source;
        }

        private void SaveDNC(List<string> NeedToDel, List<string> NeedToAdd,List<string> ALL)
        {
            DateTime BeginSaveDNC = DateTime.Now;
            #region 删除原来DNC
            HKEA_CMSEntities models = new HKEA_CMSEntities();
            var list = models.mtblDNCs.Where(a => NeedToDel.Contains(a.NumberValue));
            foreach (var temp in NeedToDel)
            {
                var tempENT = list.Where(a => a.NumberValue == temp).FirstOrDefault();
                if (tempENT != null)
                {
                    models.mtblDNCs.DeleteObject(tempENT);
                }
            }
            #endregion
            TransactionOptions options = new System.Transactions.TransactionOptions();
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout = new TimeSpan(24, 0, 0);

            HKEA_CMSEntities modelsTemp;
            int i = 1;
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                if(NeedToDel.Count > 0)
                    models.SaveChanges(); //删除的DNC被更新到数据库
                #region 由于数据量过大，大量数据导致连接超时，分批对需要被添加的DNC更新到数据库；
                modelsTemp = new HKEA_CMSEntities();
                foreach (var temp in NeedToAdd)
                {
                    if (i % 500 == 0)
                    {
                        modelsTemp.SaveChanges();
                        modelsTemp = null;
                        modelsTemp = new HKEA_CMSEntities();
                    }
                    mtblDNC ent = new mtblDNC();
                    ent.NumberValue = temp;
                    ent.ModifyBy = "";
                    ent.CreateDate = DateTime.Now;
                    modelsTemp.mtblDNCs.AddObject(ent);
                    i++;
                }
                if (modelsTemp != null)
                {
                    modelsTemp.SaveChanges();
                    modelsTemp = null;
                }
                #endregion

                TimeSpanSaveDNC = DateTime.Now - BeginSaveDNC;

                DateTime BeginUpdateInfo = DateTime.Now;
                #region 更新Info表
                modelsTemp = new HKEA_CMSEntities();
                int InfoTotalCount = models.tblContactInfoes.Where(a => a.ContactInfoUID > 0).Count();
                for (int PageNum = 1; PageNum <= Math.Ceiling((double)(InfoTotalCount / 500)); PageNum++)
                {
                    UpdateInfo(PageNum, ALL);
                }
                TimeSpanUpdateInfo = DateTime.Now - BeginUpdateInfo;
                TimeSpanFinishAll = DateTime.Now - Begin;
                #endregion

               #region 提交事务
                    try
                    {
                        scope.Complete();
                    }
                    catch (Exception er)
                    {
                        Response.Write("更新DNC失败!");
                    }
                #endregion
                    End = DateTime.Now;
                    Literal1.Text = "开始时间：" + Begin + "<br/>结束时间:" + End + "<br/>分离数据耗时：" + TimeSpanDetachALL + "<br/>分离需被删除数据耗时：" + TimeSpanGetNeedToDel + "<br/>分离需要被添加数据：" + TimeSpanGetNeedToAdd + "<br/>保存DNC信息耗时:" + TimeSpanSaveDNC + "<br/>更新Info信息耗时：" + TimeSpanUpdateInfo + "<br/>总共耗时：" + TimeSpanFinishAll;

            }
        }

        private void UpdateInfo(int pageNum,List<string> ALL)
        {
            HKEA_CMSEntities models = new HKEA_CMSEntities();
            var TempResult = models.tblContactInfoes.Where(a => a.ContactInfoUID > 0).OrderBy(a => a.ContactInfoUID).Skip((pageNum - 1) * 500).Take(500).ToList();
            foreach (var temp in TempResult)
            {
                #region 修改字段值
                // temp.Tel1_IsDNC = temp.Tel2_IsDNC = temp.Tel3_IsDNC = temp.Tel4_IsDNC = temp.Tel5_IsDNC = temp.Fax1_IsDNC = temp.Fax2_IsDNC = temp.Fax3_IsDNC = temp.Fax4_IsDNC = temp.Fax5_IsDNC = 0;
                //初始值为0；
                if (!string.IsNullOrEmpty(temp.Tel1))
                {
                    if (ALL.Contains(temp.Tel1.Replace(" ", "")) && temp.Tel1_IsDNC != 1)
                        temp.Tel1_IsDNC = 1;
                    else
                        temp.Tel1_IsDNC = 0;
                }
                if (!string.IsNullOrEmpty(temp.Tel2))
                {
                    if (ALL.Contains(temp.Tel2.Replace(" ", "")) && temp.Tel2_IsDNC != 1)
                        temp.Tel2_IsDNC = 1;
                    else
                        temp.Tel2_IsDNC = 0;
                }
                if (!string.IsNullOrEmpty(temp.Tel3))
                {
                    if (ALL.Contains(temp.Tel3.Replace(" ", "")) && temp.Tel3_IsDNC != 1)
                        temp.Tel3_IsDNC = 1;
                    else
                        temp.Tel3_IsDNC = 0;
                }
                if (!string.IsNullOrEmpty(temp.Tel4))
                {
                    if (ALL.Contains(temp.Tel4.Replace(" ", "")) && temp.Tel4_IsDNC != 1)
                        temp.Tel4_IsDNC = 1;
                    else
                        temp.Tel4_IsDNC = 0;
                }
                if (!string.IsNullOrEmpty(temp.Tel5))
                {
                    if (ALL.Contains(temp.Tel5.Replace(" ", "")) && temp.Tel5_IsDNC != 1)
                        temp.Tel5_IsDNC = 1;
                    else
                        temp.Tel5_IsDNC = 0;
                }

                if (!string.IsNullOrEmpty(temp.Fax1))
                {
                    if (ALL.Contains(temp.Fax1.Replace(" ", "")) && temp.Fax1_IsDNC != 1)
                        temp.Fax1_IsDNC = 1;
                    else
                        temp.Fax1_IsDNC = 0;
                }
                if (!string.IsNullOrEmpty(temp.Fax2))
                {
                    if (ALL.Contains(temp.Fax2.Replace(" ", "")) && temp.Fax2_IsDNC != 1)
                        temp.Fax2_IsDNC = 1;
                    else
                        temp.Fax2_IsDNC = 0;
                }
                if (!string.IsNullOrEmpty(temp.Fax3))
                {
                    if (ALL.Contains(temp.Fax3.Replace(" ", "")) && temp.Fax3_IsDNC != 1)
                        temp.Fax3_IsDNC = 1;
                    else
                        temp.Fax3_IsDNC = 0;
                }
                if (!string.IsNullOrEmpty(temp.Fax4))
                {
                    if (ALL.Contains(temp.Fax4.Replace(" ", "")) && temp.Fax4_IsDNC != 1)
                        temp.Fax4_IsDNC = 1;
                    else
                        temp.Fax4_IsDNC = 0;
                }
                if (!string.IsNullOrEmpty(temp.Fax5))
                {
                    if (ALL.Contains(temp.Fax5.Replace(" ", "")) && temp.Fax5_IsDNC != 1)
                        temp.Fax5_IsDNC = 1;
                    else
                        temp.Fax5_IsDNC = 0;
                }
                temp.LastModifyDate = DateTime.Now;
                #endregion
            }
            models.SaveChanges();
        }


        private List<string> DetachNoFromTxt()
        {
            string strFileName = "text1.txt";
            string strPath = Server.MapPath(strFileName);
            StreamReader dr = new StreamReader(strPath, System.Text.Encoding.UTF8);
            string str = dr.ReadToEnd();
            List<string> ToAdd = new List<string>();
            string[] strlist = str.Split(',');
            string[] strTemp = new string[2];
            foreach (var tempItem in strlist)
            {
                strTemp = tempItem.Split('\n');
                if (strTemp.Length == 2 && !string.IsNullOrEmpty(strTemp[1].Trim()))
                {
                    ToAdd.Add(tempItem.Split('\n')[1].Trim());
                }
            }
            dr.Close();
            return ToAdd;
        }

        private List<string> GetNeedToDelOfDNC(List<string> ALLList, List<mtblDNC> Source)
        {
            List<string> ret = new List<string>();
            var list = Source.Where(a => !ALLList.Contains(a.NumberValue.Trim())).ToList();
            foreach (var temp in list)
            {
                ret.Add(temp.NumberValue);
            }
            return ret;
        }

        private List<string> GetNeedToAddOfDNC(IList<string> ALLList, List<mtblDNC> Source)
        {
            List<string> ret = new List<string>(ALLList.ToArray());
            var list = Source.Where(a => ALLList.Contains(a.NumberValue.Trim())).ToList();
            foreach (var temp in list)
            {
                ret.Remove(temp.NumberValue.ToString());
            }
            return ret;
        }
        #endregion
        #region 更新Info信息 _Old
        //private void UpdateInfo(List<string> ALL)
        //{
        //    HKEA_CMSEntities models = new HKEA_CMSEntities();

        //    var result = models.tblContactInfoes.Where(a => a.ContactInfoUID > 0).ToList();
        //    DateTime before = DateTime.Now;
        //    int i = 1;
        //    int Count = result.Count();
        //    HKEA_CMSEntities modelsEmp;
        //    foreach (var temp in result)
        //    {
        //        modelsEmp = new HKEA_CMSEntities();
        //        if (i % 1000 == 0)
        //        {
        //            modelsEmp.SaveChanges();
        //            modelsEmp = null;
        //            modelsEmp = new HKEA_CMSEntities();
        //        }
        //    }
        //    models.SaveChanges();
        //}
        #endregion

        #region activite同步
        private tblActivite ConvertHKEAToCMS(tblActivite cms, Activity hkea)
        {
            if (cms != null && hkea!=null)
            {
                cms.Activite_Name = hkea.Title_Eng;
                cms.Activite_Theme = hkea.Title_Chi;
                cms.Activitecode = hkea.ActivityCode;
                cms.StartDateTime = hkea.StartDate;
                cms.EndDateTime = hkea.EndDate;
            }
            return cms;
        }

        private mtblActiviteType ConvertTypeHKEAToCMS(mtblActiviteType cms, ActivityType hkea)
        {
            if (cms != null && hkea != null)
            {
                cms.ActiviteType_Chi = hkea.CategoryName;
                cms.ActiviteType_Eng = hkea.CategoryName + "(from website)";
                cms.code = hkea.TypeCode;
                cms.IsFromHKEA = 1;
                cms.Deleted = 0;
            }

            return cms;
        }

        private void SyncActivity()
        {
            List<int> TypeNeedToDel = new List<int>();
            List<mtblActiviteType> TypeNeedToAdd = new List<mtblActiviteType>();
            List<mtblActiviteType> TypeNeedToUpdate = new List<mtblActiviteType>();
            var HKEA_TypeList = HKEA_TypeBLL.GetTypeList(); //获取需要整合的HKEA ActivityType所有数据
            var CMS_TypeList = CMS_TypeBLL.GetHKEAListByENT(null);
            foreach (var CMSTypeTempENT in CMS_TypeList)
            {
                TypeNeedToDel.Add(CMSTypeTempENT.ActiviteTypeUID);
            }
            foreach (var hkeaTypeTemp in HKEA_TypeList) //循环Type
            {
                mtblActiviteType cmsType = new mtblActiviteType();
                cmsType.code = hkeaTypeTemp.TypeCode;
                cmsType = CMS_TypeBLL.GetEntity(cmsType);

                #region Type处理
                if (cmsType == null)
                {
                    mtblActiviteType type = new mtblActiviteType();
                    type = ConvertTypeHKEAToCMS(type, hkeaTypeTemp);
                    TypeNeedToAdd.Add(type);
                }
                else
                {
                    cmsType = ConvertTypeHKEAToCMS(cmsType, hkeaTypeTemp);
                    TypeNeedToUpdate.Add(cmsType);
                    TypeNeedToDel.Remove(cmsType.ActiviteTypeUID);
                }

                var tempadd = TypeNeedToAdd;
                var tempupdate1 = TypeNeedToUpdate;
                var temp2 = TypeNeedToDel;
                #endregion
            }
            CMS_TypeBLL.SaveList(TypeNeedToAdd, TypeNeedToUpdate, TypeNeedToDel, Common.GetManageName());


            #region Activite 处理

            List<int> NeedToDel = new List<int>();
            List<tblActivite> NeedToAdd = new List<tblActivite>();
            List<tblActivite> NeedToUpdate = new List<tblActivite>();
            HKEA_TypeList = HKEA_TypeBLL.GetTypeList(); //重新获取 需要整合的HKEA ActivityType所有数据
            foreach (var hkeaTypeTemp in HKEA_TypeList) //循环Type
            {
                mtblActiviteType cmsType = new mtblActiviteType();
                cmsType.code = hkeaTypeTemp.TypeCode;
                cmsType = CMS_TypeBLL.GetEntity(cmsType);

                var CMS_List = cmsType.tblActivites;//得到当前hkeaTypeTemp.TypeCode下的所有CMS中 Activite
                var HKEA_List = HKEA_BLL.GetActivityList(hkeaTypeTemp.TypeCode); //得到HKEA数据库中所有该hkeaTypeTemp.TypeCode的Act
                foreach (var CMSENT in CMS_List)
                {
                    NeedToDel.Add(CMSENT.ActiviteUID); //遍历所有CMS的activityUID存放到 NeedToDel中
                }

                foreach (var HKEAENT in HKEA_List)
                {

                    var CMSENT = CMS_List.Where(a => a.Activitecode == HKEAENT.ActivityCode).FirstOrDefault();
                    if (CMSENT != null)
                    {
                        CMSENT = ConvertHKEAToCMS(CMSENT, HKEAENT);
                        CMSENT.ActiviteTypeUID = cmsType.ActiviteTypeUID;
                        NeedToUpdate.Add(CMSENT);
                        NeedToDel.Remove(CMSENT.ActiviteUID); // 将该ActivityUID重 NeedToDel中移除
                    }
                    else
                    {
                        tblActivite ent = new tblActivite();
                        ent = ConvertHKEAToCMS(ent, HKEAENT);
                        ent.ActiviteTypeUID = cmsType.ActiviteTypeUID;
                        NeedToAdd.Add(ent);
                    }
                }
            }
            #endregion

            CMS_BLL.SaveList(NeedToAdd, NeedToUpdate, NeedToDel, Common.GetManageName());
        }
        #endregion

        # warning 该页面为Brand数据转移，勿删
        private void DataBase()
        {
            stg_tblCust_Brand cust_brand = new stg_tblCust_Brand();
            stg_tblCust_BrandBLL cust_brandBLL = new stg_tblCust_BrandBLL();
            List<stg_tblCust_Brand> list = new List<stg_tblCust_Brand>();

            HKEA_CMSEntities models = new HKEA_CMSEntities();
            //var grouplist = from cust_brandtb in models.mtblBrands
            //                group cust_brandtb by new { cust_brandtb.BrandName_Eng, cust_brandtb.BrandName_Chi } into g
            //                select g;
            var grouplist = models.stg_tblCust_Brand.Where(a => a.CustBrandUID > 0).GroupBy(a => new { a.BrandName_Eng, a.BrandName_Chi });
            //插入到 Brand表中

            foreach (var listByCustomerUID in grouplist)
            {
                var temp = listByCustomerUID.FirstOrDefault();
                if (temp != null)
                {
                    mtblBrand brandENT = new mtblBrand();
                    brandENT.BrandName_Chi = temp.BrandName_Chi;
                    brandENT.CustomerUID = temp.CustomerUID;
                    brandENT.BrandName_Eng = temp.BrandName_Eng;
                    brandENT.CreationDate = temp.CreationDate;
                    brandENT.LastModifyBy = temp.LastModifyBy;
                    brandENT.LastModifyDate = temp.LastModifyDate;
                    models.mtblBrands.AddObject(brandENT);
                }
            }
            models.SaveChanges();
        }

        //brand与productcat关联到 cust_brand
        private void ToRelated()
        {
            HKEA_CMSEntities models = new HKEA_CMSEntities();
            stg_tblCust_Brand stg = new stg_tblCust_Brand();
            stg.Deleted = 0;
            stg_tblCust_BrandBLL stgBLL = new stg_tblCust_BrandBLL();
            tblBrand_ProdCatBLL cust_brandBLL = new tblBrand_ProdCatBLL();
            var liststg = stgBLL.GetListByENT(stg);
            foreach (var temp in liststg)
            {
                if (temp.ProductCatUID != null)
                {
                    mtblBrand brand = new mtblBrand();
                    var list = models.mtblBrands.Where(a => a.CustomerUID == (int)temp.CustomerUID).Where(a => a.BrandName_Chi == temp.BrandName_Chi)
                        .Where(a => a.BrandName_Eng == temp.BrandName_Eng);
                    if (list.Count() > 0)
                    {
                        foreach (var ent in list)
                        {
                            tblBrand_ProdCat cust_brand = new tblBrand_ProdCat();
                            cust_brand.CreationDate = temp.CreationDate;
                            cust_brand.Deleted = 0;
                            cust_brand.BrandUID = ent.BrandUID;
                            cust_brand.ProductCatUID = temp.ProductCatUID;
                            cust_brand.LastModifyBy = temp.LastModifyBy;
                            cust_brand.LastModifyDate = temp.LastModifyDate;
                            models.tblBrand_ProdCat.AddObject(cust_brand);
                        }
                    }
                }
            }
            models.SaveChanges();



        }

        //public delegate void GreetingDelegate(string name);
        //class Program
        //{


        //    private static void EnglishGreeting(string name)
        //    {
        //        Console.WriteLine("Morning, " + name);
        //    }

        //    private static void ChineseGreeting(string name)
        //    {
        //        Console.WriteLine("早上好, " + name);
        //    }

        //    //注意此方法，它接受一个GreetingDelegate类型的方法作为参数
        //    private static void GreetPeople(string name, GreetingDelegate MakeGreeting)
        //    {
        //        MakeGreeting(name);
        //    }

        //    static void Main(string[] args)
        //    {
        //        GreetPeople("Jimmy", EnglishGreeting);
        //        GreetPeople("China", ChineseGreeting);
        //        Console.ReadKey();
        //    }



        //List<tblCustomer> list = new List<tblCustomer>();
        //tblCustomer ent = new tblCustomer();
        //ent.CustTypeUID = 1;
        //tblCustomerBLL bll=new tblCustomerBLL();

        //var source = GetList();

        //list = bll.GetListByENT(ent);
        //tblContactInfo info = new tblContactInfo();
        //foreach (var temp in list)
        //{
        //    temp.mtblCustTypeReference.Load();

        //}
        #region
        //tblCustomer ent = DataAccess.GetModelInstance().CreateObject<tblCustomer>();
        //ent = DataAccess.GetModelInstance().tblCustomers.CreateObject();
        //ent.CustomerID = "test1";
        //ent.Name_Eng = "Update";
        //ent.CustTypeUID = 1;
        //ent.EntryDate = DateTime.Now;
        //ent.IsMember = 1;
        //ent.IsVIP = 1;
        //ent.IsGCMember = 1;
        //ent.HQLocatedinHK = 1;
        //ent.Terminated = 1;
        //ent.ContactInfoUID = 1000;
        //ent.AddressUID = 1000;
        //ent.LastModifyBy = "team";
        //ent.LastModifyDate = DateTime.Now;
        // = bll.UpDateENT(ent);

        //ent.WebSite = "www..com";

        //PageParam page = new PageParam();
        //page.CurrentPage = 1;
        //page.PageSize = 2;
        //mtblActiviteTypeBLL blls = mtblActiviteTypeBLL.GetInstance();
        //mtblActiviteType typeENT = DataAccess.GetModelInstance().mtblActiviteTypes.CreateObject();

        //typeENT.ActiviteTypeUID = 8;
        //typeENT.ActiviteType_Chi = "类别Update";
        //typeENT.ActiviteType_Eng = "EngUpdate";
        //typeENT.Deleted = 0;
        //typeENT.LastModifyBy = "team";
        //int i = blls.DeleteENT(typeENT);
        //var list = blls.GetListByENT(typeENT, page);
        //GridView1.DataSource = list;
        //GridView1.DataBind();
        //    CustomeBLL bll = new CustomeBLL();
        //    IList<tblCustomer> list = bll.GetAll();
        //    foreach (var ent in list)
        //    {
        //        foreach (var ent1 in ent.tblAct_ContactPerson)
        //        {
        //            //ent1.LastModifyBy
        //        }
        //    }
        //    GridView1.DataSource =list.Skip(1).Take(5);
        //    GridView1.DataBind();

        //    //hkea_md2Entities ctx = null;//hkea_md2Entities.();

        //    //IList<tblAct_ContactPerson> list2 = ctx.tblAct_ContactPerson.ToList();
        //    //foreach (var ent2 in list2)
        //    //{
        //    //    ent2.tblCustomer.AddressUID = 1;
        //    //} 


        //}

        #endregion
        //}


    }
}